<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>爱打印-iprint 添加帮助/广告信息</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all" />
	<link rel="stylesheet" th:href="@{/css/public.css }" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form layui-row layui-col-space10">
	<div class="layui-col-md9 layui-col-xs12">
		<div class="layui-row layui-col-space10">
			<div class="layui-col-md9 layui-col-xs7">
				<div class="layui-form-item magt3">
					<label class="layui-form-label">文章标题</label>
					<div class="layui-input-block">
						<input type="text" class="layui-input title" name="title" lay-verify="newsName" placeholder="请输入文章标题">
						<input type="hidden"  class="infoid" name="id" value="">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">内容摘要</label>
					<div class="layui-input-block">
						<textarea placeholder="请输入内容摘要" name = "infodesc" class="layui-textarea infodesc"></textarea>
					</div>
				</div>
			</div>
		</div>
		<!-- 编辑器 -->
		<div class="layui-form-item magb0">
			<label class="layui-form-label">文章内容</label>
			<div class="layui-input-block">
				<textarea class="layui-textarea layui-hide" name="content" lay-verify="content" id="info_content" ></textarea>
			</div>
		</div>
	</div>
	<div class="layui-col-md3 layui-col-xs12">
		<blockquote class="layui-elem-quote title"><i class="seraph icon-caidan"></i> 分类目录</blockquote>
		<div class="border">
			<div class="categoryaa">
				<p><input type="radio" name="category" value="helpinfo" title="帮助信息" lay-skin="primary" /></p>
				<p><input type="radio" name="category" value="adsinfo" title="广告信息" lay-skin="primary" /></p>
			</div>
		</div>
		<blockquote class="layui-elem-quote title magt10"><i class="layui-icon">&#xe609;</i> 发布</blockquote>
		<div class="border">
			<div class="layui-form-item">
				<label class="layui-form-label"><i class="layui-icon">&#xe60e;</i> 状　态</label>
				<div class="layui-input-block infoStatus">
					<select name="state" lay-verify="required">
						<option value="0" >保存草稿</option>
						<option value="1">立即发布</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item top">
				<label class="layui-form-label"><i class="seraph icon-look"></i> 是否置顶</label>
				<div class="layui-input-block">
					<input type="radio" name="top" value="1" title="置顶" lay-skin="primary"  />
					<input type="radio" name="top" value="0" title="不置顶" lay-skin="primary" checked/>
				</div>
			</div>
			<hr class="layui-bg-gray" />
			<div class="layui-right">
				<a class="layui-btn layui-btn-sm" lay-filter="addNews" lay-submit><i class="layui-icon">&#xe609;</i>发布</a>
				<a class="layui-btn layui-btn-primary layui-btn-sm" lay-filter="look" lay-submit>预览</a>
			</div>
		</div>
	</div>
</form>
<script type="text/javascript" th:src="@{/layui/layui.js}"></script>
<script type="text/javascript" >
	layui.use(['form','layer','layedit','laydate','upload'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        laypage = layui.laypage,
        upload = layui.upload,
        layedit = layui.layedit,
        laydate = layui.laydate,
        $ = layui.jquery;

    	//用于同步编辑器内容到textarea
	    layedit.sync(editIndex);
	    //格式化时间
	    function filterTime(val){
	        if(val < 10){
	            return "0" + val;
	        }else{
	            return val;
	        }
	    }

	    form.verify({
	        /*newsName : function(val){
	            if(val == ''){
	                return "文章标题不能为空";
	            }
	        },
	        content : function(val){
	            if(val == ''){
	                return "文章内容不能为空";
	            }
	        }*/
	    })
    form.on("submit(addNews)",function(data){
        //截取文章内容中的一部分文字放入文章摘要
        var abstracta = layedit.getText(editIndex).substring(0,50);
      	var jsonInof =  data.field;
      	jsonInof.content = layedit.getContent(editIndex).split('<audio controls="controls" style="display: none;"></audio>')[0];
      	//弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        // 实际使用时的提交信息
          $.ajax({
				cache:true,
				type:"POST",
				url:"/iprint/admin/addInfo",
				contentType:"application/json;charset=utf-8",
				data:JSON.stringify(jsonInof), 
				async:true,
				success:function(data){
				}
			}); 
         setTimeout(function(){
            top.layer.close(index);
            top.layer.msg("文章添加成功！");
            layer.closeAll("iframe");
            //刷新父页面
            parent.location.reload();
        },500); 
        return false;
    })

    //预览
    form.on("submit(look)",function(){
        layer.alert("此功能需要前台展示，实际开发中传入对应的必要参数进行文章内容页面访问");
        return false;
    })

    //创建一个编辑器
    var editIndex = layedit.build('info_content',{
        height : 535
    });
})
</script>
</body>
</html>